//
//  UpdateCarCell.swift
//  koolcar
//
//  Created by kuaimaxiansheng on 2023/10/23.
//

import UIKit

class UpdateCarCell: UICollectionViewCell {
    var bkgView: UIView!
    var addBtn: UIButton!
    var imgView: UIImageView!
    var deleteBtn: UIButton!
    var atIndex: NSInteger = 0
    var statusLab: UILabel!
    override init(frame: CGRect) {
        super.init(frame: frame)
   
        bkgView = UIView.init(frame: CGRect.zero)
        bkgView.backgroundColor = UIColor.white
        bkgView.layer.cornerRadius = 8
        bkgView.layer.masksToBounds = true
        self.contentView.addSubview(bkgView)
        
        addBtn = UIButton.init(frame: CGRect.zero)
        addBtn.setImage(UIImage.init(named: "icon_photo_add"), for: .normal)
        addBtn.setImage(UIImage.init(named: "icon_photo_add"), for: .highlighted)
        addBtn.addTarget(self, action: #selector(addBtnAction), for: .touchUpInside)
        bkgView.addSubview(addBtn)
        
        imgView = UIImageView.init(frame: CGRect.init(x: 4, y: 4, width: 80, height: 80))
        imgView.contentMode = .scaleAspectFill
        imgView.backgroundColor = UIColor.clear
        imgView.clipsToBounds = true
        bkgView.addSubview(imgView)
        
//        statusLab = UILabel.init()
//        alphaView.backgroundColor = UIColor.init(hex: 0x000000, alpha: 0.7)
//        imgView.addSubview(alphaView)
        
        statusLab = UILabel.init(frame: CGRect.init())
        statusLab.backgroundColor = UIColor.init(hex: 0x000000, alpha: 0.7)
        statusLab.textAlignment = .center
        statusLab.font = UIFont.systemFont(ofSize: 10)
        statusLab.textColor = UIColor.white
        imgView.addSubview(statusLab)
        
        deleteBtn = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 20, height: 20))
        deleteBtn.setImage(UIImage.init(named: "icon_img_delete"), for: .normal)
        deleteBtn.setImage(UIImage.init(named: "icon_img_delete"), for: .highlighted)
        deleteBtn.addTarget(self, action: #selector(deleteBtnAction), for: .touchUpInside)
        self.contentView.addSubview(deleteBtn)
        
        self.addSnpLayout()
    }
    
    func addSnpLayout() {
        bkgView.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.top.equalTo(4)
            make.right.equalTo(0)
            make.height.equalTo(75)
        }
        
        addBtn.snp.makeConstraints { make in
            make.left.right.equalTo(0)
            make.top.bottom.equalTo(0)
        }
        
        imgView.snp.makeConstraints { make in
            make.left.right.top.bottom.equalTo(0)
        }
        
        statusLab.snp.makeConstraints { make in
            make.left.right.top.bottom.equalTo(0)
        }
        
        deleteBtn.snp.makeConstraints { make in
            make.right.equalTo(3)
            make.top.equalTo(-3)
            make.size.equalTo(CGSize.init(width: 20, height: 20))
        }
    }
    
    ///样式
    func setFreeValuationUploadImgItemCellType(showBtn: Bool) {
        if showBtn {
            self.addBtn.isHidden = false
            self.imgView.isHidden = true
            self.deleteBtn.isHidden = true
        }else{
            self.addBtn.isHidden = true
            self.imgView.isHidden = false
            self.deleteBtn.isHidden = false
        }
    }
    
    ///添加照片事件
    @objc func addBtnAction(){
//        self.delegate?.addImageAction()
    }
    
    ///删除照片事件
    @objc func deleteBtnAction(){
//        self.delegate?.deleteImageAction(atIndex: self.atIndex)
    }
    
    ///赋值
    func setUpLoadImgModel(itemModel: UpLoadImgModel) {
        self.statusLab.isHidden = false
        self.imgView.image = itemModel.image
        switch itemModel.uploadStatus {
        case 1:
            //上传成功
            self.statusLab.isHidden = true
        case 2:
            //上传失败
            statusLab.text = "上传失败"
        default:
            statusLab.text = "上传中"
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

